layui.use(['form', 'table', 'layer', 'laydate'], function (form, table, layer, laydate) {
    //提交按钮监听
    form.on("submit(updateSubmit)", function (data) {
        const userInfo = data.field;
        console.log("用户信息:", JSON.stringify(userInfo));
        $.ajax({
            type: "post",
            url: "../user/update",
            data: JSON.stringify(userInfo),
            headers: {
                'Content-Type': 'application/json;charset=utf-8'
            },
            success: function (data) {
                if (parseInt(data.obj) > 0) {
                    layer.closeAll();
                    layer.msg(
                        '修改成功',
                        {
                            icon: 1,
                            time: 1000
                        },
                        function () {
                            window.location.reload();
                            location.href="admin.html";
                        });
                } else {
                    layer.msg('修改失败', {icon: 2});
                }
            },
            error: function (o) {
            }
        });
        return false;
    });

    //返回 return
    $(document).on("click", "#returnShow", function () {
        window.location.href = "phone-main.html";
    });

    //回显数据
    layer.ready(function () {
        $.ajax({
            url: "../user/" + parseInt(Base64.decode(getToken())),
            success: function (data) {
                const user = data.obj;
                console.log("user", user);
                //给表单赋值
                form.val("personal_form", { //formTest 即 class="layui-form" 所在元素属性 lay-filter="" 对应的值
                    "username": user.username
                    , "password": user.password
                    , "nickname": user.nickname
                    , "mail": user.mail
                    , "mailpwd": user.mailpwd
                    , "age": user.age
                    , "sex": user.sex
                    , "phone": user.phone
                    , "address": user.address
                });
            }
        });
    });

    form.render();//重点在这里
});